<template>
<div class="cdsz_box">
    <header-comm></header-comm>
 <div class="bcg">
  <div class="glwz_box">
    <div class="header_sele">
      <div class="add_qy">
           <!--  -->
           <a-button type="primary" @click="newadd">添加菜单</a-button>
           <!-- <a-button type="primary" @click="modifyPass">修改密码</a-button> -->
      </div>
      
      <div>
        <!-- 添加菜单 -->
        <div class="gl_tjwz" v-if="$store.state.tjwz">
          <cdsztk class="gl_tjym"></cdsztk>
        </div>
        <!-- 修改密码 -->
        <div class="gl_tjwz" v-if="xgmm">
          <xgmm class="gl_tjym"></xgmm>
        </div>
        <!-- <div class="seach">
           <a-button type="primary" @click="rushcacho">清除缓存</a-button>
        </div>  -->
      </div>
    </div>
    <div class="glwz">
      <a-table
        @change="handleChangelist"
         slot="expandedRowRender"
        :loading="loading"
        :columns="columns"
        :pagination="pagination"
        :dataSource="data"
        :defaultExpandAllRows="true"
      >

         
 <template  slot="img" slot-scope="text, record, index">
         <img class="chilpic" v-if="text!=null" :src="text" alt="">
          <!-- {{text}} -->
        </template>
        <template slot="operation" slot-scope="text, record, index">
          <div class="editable-row-operations">

            <a class="del" v-if="record.parentid==0"  @click="()=>addcd(record,record.key,record.parentid)">添加子菜单</a>
            <a class="del" @click="()=>xiugai(record,record.key)">修改</a>
            <a-popconfirm class="del" title="确定删除吗?" @confirm="() => wzdelete(record,record.key)">
              <a>删除</a>
            </a-popconfirm>
          </div>
        </template>
       
      </a-table>
    </div>
    <!-- 表格-================= -->
  </div>
 </div>
  </div>

</template>

<script>
import headerComm from "../header-comm/header.vue";
import cdsztk from "./cdsztk.vue";
import xgmm from "./xgmm.vue";

const columns = [
  {
    title: "名称",
    dataIndex: "cnName",
      scopedSlots: { customRender: 'cnName' },
  },
  {
    title: "链接地址",
    dataIndex: "url",
    scopedSlots: { customRender: "url" },
   
  },
  {
    title: "图片",
    dataIndex: "img",
    scopedSlots: { customRender: "img" },

  },
   {
    title: "排序",
    dataIndex: "sort",
    scopedSlots: { customRender: "sort" },

  },
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" }
  }
];

// 二级菜单--开始
 const innerColumns = [
    { title: '名称', dataIndex: 'cnName', 
      scopedSlots: { customRender: 'cnName' },
    
    },
    { title: '链接地址', dataIndex: 'url' },
    { title: '图片',  dataIndex: 'img' },
    {
      title: 'Action',
      dataIndex: 'operation',
      key: 'operation',
      scopedSlots: { customRender: 'operation' },
    },
  ];
 const innerData = [];
  // for (let i = 0; i < 3; ++i) {
  //   innerData.push({
  //     key: i,
  //     cnName: '2014-12-24 23:12:00',
  //     url: 'This is production name',
  //     img: 'This is production name',
  //   });
  // }
// 二级菜单--结束

const data = [];
import qs from "qs";

export default {
  data() {
    this.cacheData = data.map(item => ({ ...item }));

    return {
      data,
      columns,
       innerColumns,
        innerData,
      sele: "",
      // serchvalue: "",
      pagination: {
        defaultPageSize: 10,
        showTotal: total => `共 ${total} 条数据`,
        total: 0
      },
      loading: true,
      langtklist:'',
      addlang:false,
      addnewcd:true,
      //修改密码
      xgmm:false

    };
  },
  components: {
    headerComm,
    cdsztk,
    xgmm
  },
  methods: {
    // //搜索框
    // onSearch(e) {
    //   this.serchvalue = e.target.value;
    //   this.handleChangelist(this.pagination, this.serchvalue);
    // },
   
    //获取语言列表
    handleChangelist(pagination) {
      this.axios
        .post(
          "set/webSiteList.php",
          qs.stringify({
            page: pagination.current,
            pageSize: pagination.defaultPageSize,
            sqdwid:this.$store.state.bbl_sqdwid,

          })
        )
        .then(res => {
            console.log(res)
          if (res.data.code == 303) {
            this.data = res.data.result;
           for(var i=0;i<this.data.length;i++){
              this.data[i].key = res.data.result[i].id_num;

            if(this.data[i].children){
               for (let j = 0; j < this.data[i].children.length; j++) {
                 this.data[i].children[j].key=this.data[i].children[j].id_num
              }
            }

             
           }
            this.pagination.total = Number(res.data.result.total);
            this.loading = false;
            this.cacheData = this.data.map(item => ({
              ...item
            }));
          
          } else {
            this.data = [];
            this.loading = false;
          }
        });
    },

    //删除
    wzdelete(value, key) {
      console.log(value)
      const dataSource = [...this.data];
      this.data = dataSource.filter(item => item.key !== key);
      this.axios
        .post(
          "set/webSiteDelete.php",
          qs.stringify({ id_num: value.id_num })
        )
        .then(res => {
          if (res.data.code == 303) {
              this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
            if(value.parentid!=0){
               this.handleChangelist(this.pagination,this.serchvalue ) 
               console.log(value.parentid)
            }
          
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
    modifyPass(){
      this.xgmm = true;
    },
    newadd(){
      this.$store.state.tjwz = true;
      this.addlang=true;
      this.addnewcd=false
    },
   addcd(value,key){
      this.$store.state.tjwz = true;
      this.addlang=true;
      this.addnewcd=true
      this.langtklist=value
      console.log(value)
    },
     rushcacho(){
     let language=JSON.parse(sessionStorage.getItem("language"))
 this.axios
        .get(
          "http://"+language.domainName+"/resetCache/deleteCache?updata=5655840!"
        )
        .then(res => {
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
   },

   
    //打开添加文章面板
    tjwz() {
      this.addlang=false;
      this.$store.state.tjwz = true;
    },

    //文字修改
    xiugai(value, key) {
        console.log(value)
        this.langtklist=value
      this.$store.state.tjwz = true;
    },
  },
 
  created() {
    let language=JSON.parse(sessionStorage.getItem("language"))
  
    this.handleChangelist(this.pagination, this.serchvalue);
 
  }
};
</script>

<style lang='less'>
.cdsz_box {
  .gl_tjwz {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999999999;
    height: 930px;
    .gl_tjym {
      position: absolute;
      width: 80%;
      left: 50%;
      transform: translateX(-50%);
    }
  }
  .header_sele {
    position: absolute;
    top: 55px;
    left: 1% !important;
    z-index: 999;
    text-align: right;
    width: 98%!important;
    background-color: #fff;
    box-shadow: 5px 5px 5px #ccc;
    // height: 50px;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .add_qy {
      // width: 50%;
      display: inline-block;
      text-align: left;
      padding: 10px 0;
      height: 50px !important;
      button {
        margin: 0 10px;
      }
      .ant-btn-primary {
        background-color: #1890ff !important;
        border: 0 !important;
      }
    }
    .seach {
      display: inline-block;
      .sele {
        position: relative;
        i {
          position: absolute;
          top: 10px;
          right: 8px;
        }
      }
    }
    .list_head {
      display: inline-block;
      .tit {
        font-size: 16px;
      }
      padding: 10px 15px;
      .fl_right {
        .margin {
          margin: 0 5px;
        }
        .xzl_btn:hover {
          border: 0 !important;
          color: #fff !important;
          background: #1890ff !important;
        }
      }
    }
  }
  .glwz {
    width: 98%;
    position: relative;
    top: 147px;
    left: 1%;
    background-color: #fff;
    border: 1px solid #ccc;
  .chilpic{
    width: 45px;
  }
    .ant-table-thead > tr,
    .ant-table-tbody > tr {
      height: 50px !important;
    }

    .ant-table-tbody  tr td{
         overflow: hidden;/*超出部分隐藏*/
            white-space: nowrap;/*不换行*/
            text-overflow:ellipsis;/*超出部分文字以...显示*/
            max-width: 200px;
            padding: 0px 16px!important;
    }
    .ant-table .ant-table-row-indent + .ant-table-row-expand-icon{
      position: absolute;
      left: 25px;
    }
    .ant-table-row-level-1{
      background-color: #f7f7f7;
      td{
        // text-align: left;
      }
    }
    .del {
    }
  }
}

.fyloading {
  position: absolute;
  width: 90% !important;
  border: 1px solid #91d5ff;
  background: rgba(255, 255, 255, 0.5);
  padding: 30px;
  height: 800px !important;
  z-index: 999999 !important;
  top: 108px;
  left: 201px;
  .ant-spin-blur {
    opacity: 1 !important;
  }
  .ant-spin-text {
    font-size: 18px !important;
  }

}
.ant-spin-nested-loading > div > .ant-spin {
  top: 100px !important;
}
.del {
  padding-right: 15px;
  color: #40a9ff;
  cursor: pointer;
}
</style>
